]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
apps: Ensure running apps override new .desktop file data
authorColin Walters <walters@verbum.org>
Sat, 3 Sep 2011 14:32:06 +0000 (10:32 -0400)
committerColin Walters <walters@verbum.org>
Mon, 5 Sep 2011 21:29:41 +0000 (17:29 -0400)
This patch fixes the "apps vanish from alt-TAB bug".

If a "package system" rips away and possibly replaces .desktop files
at some random time, we have historically used inotify to detect this
and reread state (in a racy way, but...).  In GNOME 2, this was
generally not too problematic because the menu widget was totally
separate from the list of windows - and the data they operate on was
disjoint as well.

In GNOME 3 we unify these, and this creates architectural problems
because the windows are tied to the app.

What this patch tries to do is, when rereading the application state,
if we have a running application, we keep that app around instead of
making a new instance.  This ensures we preserve any state such as the
set of open windows.

This requires moving the running state into ShellAppSystem.  Adjust
callers as necessary, and while we're at it drop the unused "contexts"
stuff.

This is just a somewhat quick band-aid; a REAL fix would require us
having low-level control over application installation.  As long as
we're on top of random broken tar+wget wrappers, it will be gross.

A slight future improvement to this patch would add an explicit
"merge" between the old and new data.  I think probably we always keep
around the ShellApp corresponding to a given ID, but replace its
GMenuTreeEntry.

https://bugzilla.gnome.org/show_bug.cgi?id=657990

js/ui/altTab.js
js/ui/dash.js
js/ui/panel.js
src/Makefile.am
src/shell-app-system-private.h [new file with mode: 0644]
src/shell-app-system.c
src/shell-app-system.h
src/shell-app.c
src/shell-window-tracker-private.h
src/shell-window-tracker.c
src/shell-window-tracker.h

index b1a12eb155b901204f54d56530f4180c3787a7c7..0d2ae3960eb5b8e4b5999bc59bbfea13035e3c9e 100644 (file)
@@ -122,8 +122,8 @@ AltTabPopup.prototype = {
     },
 
     show : function(backward, binding) {
-        let tracker = Shell.WindowTracker.get_default();
-        let apps = tracker.get_running_apps ('');
+        let appSys = Shell.AppSystem.get_default();
+        let apps = appSys.get_running ();
 
         if (!apps.length)
             return false;
index 77d4eb4a02654a0dff0149b8d43890b9f7c4f68b..e96ae9eeba5b38bf642f9256c769cec850509879 100644 (file)
@@ -275,7 +275,7 @@ Dash.prototype = {
 
         this._appSystem.connect('installed-changed', Lang.bind(this, this._queueRedisplay));
         AppFavorites.getAppFavorites().connect('changed', Lang.bind(this, this._queueRedisplay));
-        this._tracker.connect('app-state-changed', Lang.bind(this, this._queueRedisplay));
+        this._appSystem.connect('app-state-changed', Lang.bind(this, this._queueRedisplay));
 
         Main.overview.connect('item-drag-begin',
                               Lang.bind(this, this._onDragBegin));
@@ -471,10 +471,7 @@ Dash.prototype = {
     _redisplay: function () {
         let favorites = AppFavorites.getAppFavorites().getFavoriteMap();
 
-        /* hardcode here pending some design about how exactly desktop contexts behave */
-        let contextId = '';
-
-        let running = this._tracker.get_running_apps(contextId);
+        let running = this._appSystem.get_running();
 
         let children = this._box.get_children().filter(function(actor) {
                 return actor._delegate.child &&
index 987ca2b8c45d68cf56a10d6ce140b767cf76216d..57c5df4aa247045c173ed3fe13b511461af22c3d 100644 (file)
@@ -292,8 +292,9 @@ AppMenuButton.prototype = {
         this._spinner.actor.lower_bottom();
 
         let tracker = Shell.WindowTracker.get_default();
+        let appSys = Shell.AppSystem.get_default();
         tracker.connect('notify::focus-app', Lang.bind(this, this._sync));
-        tracker.connect('app-state-changed', Lang.bind(this, this._onAppStateChanged));
+        appSys.connect('app-state-changed', Lang.bind(this, this._onAppStateChanged));
 
         global.window_manager.connect('switch-workspace', Lang.bind(this, this._sync));
 
@@ -457,7 +458,7 @@ AppMenuButton.prototype = {
         this._targetApp.request_quit();
     },
 
-    _onAppStateChanged: function(tracker, app) {
+    _onAppStateChanged: function(appSys, app) {
         let state = app.state;
         if (state != Shell.AppState.STARTING) {
             this._startingApps = this._startingApps.filter(function(a) {
index 3ff043f61f0a0f801391d95f68e7d2f5245f0aaa..11449eac574bfa47203e41d35428f271ca43c5ea 100644 (file)
@@ -126,6 +126,7 @@ libgnome_shell_la_SOURCES =         \
        $(shell_built_sources)          \
        $(shell_public_headers_h)       \
        shell-app-private.h             \
+       shell-app-system-private.h      \
        shell-embedded-window-private.h \
        shell-global-private.h          \
        shell-jsapi-compat-private.h    \
diff --git a/src/shell-app-system-private.h b/src/shell-app-system-private.h
new file mode 100644 (file)
index 0000000..975d563
--- /dev/null
@@ -0,0 +1,9 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+#ifndef __SHELL_APP_SYSTEM_PRIVATE_H__
+#define __SHELL_APP_SYSTEM_PRIVATE_H__
+
+#include "shell-app-system.h"
+
+void _shell_app_system_notify_app_state_changed (ShellAppSystem *self, ShellApp *app);
+
+#endif
index 4bdfc801c1e0f276fb1d39f6786ccb5c31335f35..4d3d76ebfa683e002b06090a9eb47516e75bd025 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "shell-app-private.h"
 #include "shell-window-tracker-private.h"
+#include "shell-app-system-private.h"
 #include "shell-global.h"
 #include "shell-util.h"
 #include "st.h"
@@ -32,6 +33,7 @@ enum {
 };
 
 enum {
+  APP_STATE_CHANGED,
   INSTALLED_CHANGED,
   LAST_SIGNAL
 };
@@ -43,6 +45,8 @@ struct _ShellAppSystemPrivate {
 
   GHashTable *entry_to_app;
 
+  GHashTable *running_apps;
+
   GSList *known_vendor_prefixes;
 
   GMenuTree *settings_tree;
@@ -61,6 +65,14 @@ static void shell_app_system_class_init(ShellAppSystemClass *klass)
 
   gobject_class->finalize = shell_app_system_finalize;
 
+  signals[APP_STATE_CHANGED] = g_signal_new ("app-state-changed",
+                                             SHELL_TYPE_APP_SYSTEM,
+                                             G_SIGNAL_RUN_LAST,
+                                             0,
+                                             NULL, NULL,
+                                             g_cclosure_marshal_VOID__OBJECT,
+                                             G_TYPE_NONE, 1,
+                                             SHELL_TYPE_APP);
   signals[INSTALLED_CHANGED] =
     g_signal_new ("installed-changed",
                  SHELL_TYPE_APP_SYSTEM,
@@ -82,6 +94,9 @@ shell_app_system_init (ShellAppSystem *self)
                                                    SHELL_TYPE_APP_SYSTEM,
                                                    ShellAppSystemPrivate);
 
+  priv->running_apps = g_hash_table_new_full (g_str_hash, g_str_equal,
+                                              NULL, (GDestroyNotify) g_object_unref);
+
   priv->entry_to_app = g_hash_table_new_full (NULL, NULL,
                                               (GDestroyNotify)gmenu_tree_item_unref,
                                               (GDestroyNotify)g_object_unref);
@@ -112,6 +127,7 @@ shell_app_system_finalize (GObject *object)
   g_object_unref (priv->apps_tree);
   g_object_unref (priv->settings_tree);
 
+  g_hash_table_destroy (priv->running_apps);
   g_hash_table_destroy (priv->entry_to_app);
   g_hash_table_destroy (priv->setting_entry_to_app);
 
@@ -248,7 +264,14 @@ load_app_entry (ShellAppSystem *self,
   else
     g_free (prefix);
 
-  app = _shell_app_new (entry);
+  /* Here we check to see whether the app is still running; if so, we
+   * keep the old data around.
+   */
+  app = g_hash_table_lookup (self->priv->running_apps, gmenu_tree_entry_get_desktop_file_id (entry));
+  if (app != NULL)
+    app = g_object_ref (app);
+  else
+    app = _shell_app_new (entry);
 
   g_hash_table_insert (self->priv->entry_to_app, gmenu_tree_item_ref (entry), app);
 }
@@ -492,7 +515,10 @@ ShellApp *
 shell_app_system_lookup_app_by_tree_entry (ShellAppSystem  *self,
                                            GMenuTreeEntry  *entry)
 {
-  return g_hash_table_lookup (self->priv->entry_to_app, entry);
+  /* If we looked up directly in ->entry_to_app, we'd lose the
+   * override of running apps.  Thus, indirect through the id.
+   */
+  return shell_app_system_lookup_app (self, gmenu_tree_entry_get_desktop_file_id (entry));
 }
 
 /**
@@ -582,12 +608,67 @@ shell_app_system_get_all (ShellAppSystem  *self)
   while (g_hash_table_iter_next (&iter, &key, &value))
     {
       ShellApp *app = value;
+      
       if (!g_desktop_app_info_get_nodisplay (shell_app_get_app_info (app)))
         result = g_slist_prepend (result, app);
     }
   return result;
 }
 
+void
+_shell_app_system_notify_app_state_changed (ShellAppSystem *self,
+                                            ShellApp       *app)
+{
+  ShellAppState state = shell_app_get_state (app);
+
+  switch (state)
+    {
+    case SHELL_APP_STATE_RUNNING:
+      /* key is owned by the app */
+      g_hash_table_insert (self->priv->running_apps, (char*)shell_app_get_id (app), g_object_ref (app));
+      break;
+    case SHELL_APP_STATE_STARTING:
+      break;
+    case SHELL_APP_STATE_STOPPED:
+      g_hash_table_remove (self->priv->running_apps, shell_app_get_id (app));
+      break;
+    }
+  g_signal_emit (self, signals[APP_STATE_CHANGED], 0, app);
+}
+
+/**
+ * shell_app_system_get_running:
+ * @self: A #ShellAppSystem
+ *
+ * Returns the set of applications which currently have at least one
+ * open window in the given context.  The returned list will be sorted
+ * by shell_app_compare().
+ *
+ * Returns: (element-type ShellApp) (transfer container): Active applications
+ */
+GSList *
+shell_app_system_get_running (ShellAppSystem *self)
+{
+  gpointer key, value;
+  GSList *ret;
+  GHashTableIter iter;
+
+  g_hash_table_iter_init (&iter, self->priv->running_apps);
+
+  ret = NULL;
+  while (g_hash_table_iter_next (&iter, &key, &value))
+    {
+      ShellApp *app = value;
+
+      ret = g_slist_prepend (ret, app);
+    }
+
+  ret = g_slist_sort (ret, (GCompareFunc)shell_app_compare);
+
+  return ret;
+}
+
+
 static gint
 compare_apps_by_name (gconstpointer a,
                       gconstpointer b,
index a2a55f6462b4b4e15333a7cb56336f82bbdab484..c26b72859d99359935b97ba1d4df0237d99ebed6 100644 (file)
@@ -53,6 +53,8 @@ ShellApp       *shell_app_system_lookup_heuristic_basename    (ShellAppSystem  *
 
 GSList         *shell_app_system_get_all                   (ShellAppSystem  *system);
 
+GSList         *shell_app_system_get_running               (ShellAppSystem  *self);
+
 GSList         *shell_app_system_initial_search            (ShellAppSystem  *system,
                                                             GSList          *terms);
 GSList         *shell_app_system_subsearch                 (ShellAppSystem  *system,
index 0455f42b4426209fcd1b6dd0e781818cc03ca75d..7535a8199380a856e5dcce0b57eed3288a1ce029 100644 (file)
@@ -12,6 +12,7 @@
 #include "shell-enum-types.h"
 #include "shell-global.h"
 #include "shell-util.h"
+#include "shell-app-system-private.h"
 #include "shell-window-tracker-private.h"
 #include "st.h"
 
@@ -840,7 +841,7 @@ shell_app_state_transition (ShellApp      *app,
       app->running_state = NULL;
     }
 
-  _shell_window_tracker_notify_app_state_changed (shell_window_tracker_get_default (), app);
+  _shell_app_system_notify_app_state_changed (shell_app_system_get_default (), app);
 
   g_object_notify (G_OBJECT (app), "state");
 }
index 0b60a8896a38336911936ae4c1b5f3d17f0a62cc..4307d153a0d99fce692186f1e645a6a89bc05660 100644 (file)
@@ -4,8 +4,6 @@
 
 #include "shell-window-tracker.h"
 
-void _shell_window_tracker_notify_app_state_changed (ShellWindowTracker *tracker, ShellApp *self);
-
 void _shell_window_tracker_add_child_process_app (ShellWindowTracker *tracker,
                                                   GPid                pid,
                                                   ShellApp           *app);
index 3ad7dd4ab24cdb4397e1efd2934f5532254aa986..b0251d27071277a83645597f47f4fc4e69d88394 100644 (file)
@@ -49,9 +49,6 @@ struct _ShellWindowTracker
   /* <MetaWindow * window, ShellApp *app> */
   GHashTable *window_to_app;
 
-  /* <const char *id, ShellApp *app> */
-  GHashTable *running_apps;
-
   /* <int, ShellApp *app> */
   GHashTable *launched_pid_to_app;
 };
@@ -64,7 +61,6 @@ enum {
 };
 
 enum {
-  APP_STATE_CHANGED,
   STARTUP_SEQUENCE_CHANGED,
   TRACKED_WINDOWS_CHANGED,
 
@@ -117,14 +113,6 @@ shell_window_tracker_class_init (ShellWindowTrackerClass *klass)
                                                         SHELL_TYPE_APP,
                                                         G_PARAM_READABLE));
 
-  signals[APP_STATE_CHANGED] = g_signal_new ("app-state-changed",
-                                             SHELL_TYPE_WINDOW_TRACKER,
-                                             G_SIGNAL_RUN_LAST,
-                                             0,
-                                             NULL, NULL,
-                                             g_cclosure_marshal_VOID__OBJECT,
-                                             G_TYPE_NONE, 1,
-                                             SHELL_TYPE_APP);
   signals[STARTUP_SEQUENCE_CHANGED] = g_signal_new ("startup-sequence-changed",
                                    SHELL_TYPE_WINDOW_TRACKER,
                                    G_SIGNAL_RUN_LAST,
@@ -579,27 +567,6 @@ init_window_tracking (ShellWindowTracker *self)
   shell_window_tracker_on_n_workspaces_changed (screen, NULL, self);
 }
 
-void
-_shell_window_tracker_notify_app_state_changed (ShellWindowTracker *self,
-                                                ShellApp           *app)
-{
-  ShellAppState state = shell_app_get_state (app);
-
-  switch (state)
-    {
-    case SHELL_APP_STATE_RUNNING:
-      /* key is owned by the app */
-      g_hash_table_insert (self->running_apps, (char*)shell_app_get_id (app), app);
-      break;
-    case SHELL_APP_STATE_STARTING:
-      break;
-    case SHELL_APP_STATE_STOPPED:
-      g_hash_table_remove (self->running_apps, shell_app_get_id (app));
-      break;
-    }
-  g_signal_emit (self, signals[APP_STATE_CHANGED], 0, app);
-}
-
 static void
 on_startup_sequence_changed (MetaScreen            *screen,
                              SnStartupSequence     *sequence,
@@ -622,8 +589,6 @@ shell_window_tracker_init (ShellWindowTracker *self)
   self->window_to_app = g_hash_table_new_full (g_direct_hash, g_direct_equal,
                                                NULL, (GDestroyNotify) g_object_unref);
 
-  self->running_apps = g_hash_table_new (g_str_hash, g_str_equal);
-
   self->launched_pid_to_app = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_object_unref);
 
   screen = shell_global_get_screen (shell_global_get ());
@@ -640,7 +605,6 @@ shell_window_tracker_finalize (GObject *object)
 {
   ShellWindowTracker *self = SHELL_WINDOW_TRACKER (object);
 
-  g_hash_table_destroy (self->running_apps);
   g_hash_table_destroy (self->window_to_app);
   g_hash_table_destroy (self->launched_pid_to_app);
 
@@ -686,7 +650,7 @@ ShellApp *
 shell_window_tracker_get_app_from_pid (ShellWindowTracker *self, 
                                        int                 pid)
 {
-  GSList *running = shell_window_tracker_get_running_apps (self, "");
+  GSList *running = shell_app_system_get_running (shell_app_system_get_default());
   GSList *iter;
   ShellApp *result = NULL;
 
@@ -716,43 +680,6 @@ shell_window_tracker_get_app_from_pid (ShellWindowTracker *self,
   return result;
 }
 
-/**
- * shell_window_tracker_get_running_apps:
- * @tracker: An app monitor instance
- * @context: Activity identifier
- *
- * Returns the set of applications which currently have at least one open
- * window in the given context.  The returned list will be sorted
- * by shell_app_compare().
- *
- * Returns: (element-type ShellApp) (transfer full): Active applications
- */
-GSList *
-shell_window_tracker_get_running_apps (ShellWindowTracker *tracker,
-                                       const char         *context)
-{
-  gpointer key, value;
-  GSList *ret;
-  GHashTableIter iter;
-
-  g_hash_table_iter_init (&iter, tracker->running_apps);
-
-  ret = NULL;
-  while (g_hash_table_iter_next (&iter, &key, &value))
-    {
-      ShellApp *app = value;
-
-      if (strcmp (context, _shell_window_tracker_get_app_context (tracker, app)) != 0)
-        continue;
-
-      ret = g_slist_prepend (ret, g_object_ref (app));
-    }
-
-  ret = g_slist_sort (ret, (GCompareFunc)shell_app_compare);
-
-  return ret;
-}
-
 static void
 on_child_exited (GPid      pid,
                  gint      status,
index 62bb5b238193cc8bd9afc35a143f578e35614e5c..99c4cf618f85e43c6c0dd8dd0b4ee4a613342e23 100644 (file)
@@ -31,9 +31,6 @@ GType shell_window_tracker_get_type (void) G_GNUC_CONST;
 
 ShellWindowTracker* shell_window_tracker_get_default(void);
 
-GSList * shell_window_tracker_get_running_apps (ShellWindowTracker *tracker,
-                                                const char         *context);
-
 ShellApp *shell_window_tracker_get_window_app (ShellWindowTracker *tracker, MetaWindow *metawin);
 
 ShellApp *shell_window_tracker_get_app_from_pid (ShellWindowTracker *tracker, int pid);